package com.集合.Collection.练习;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;

/**
 * @Author CT
 * @Date 2021/6/21 11:08 下午
 */
public class Collection集合存储学生对象并遍历集合 {
    public static void main(String[] args) {
        Collection<Student> c = new ArrayList<Student>();

        Student s1 = new Student("小张", 35);
        Student s2 = new Student("小李", 33);
        Student s3 = new Student("小王", 38);

        c.add(s1);
        c.add(s2);
        c.add(s3);

        // 遍历集合
        Iterator<Student> it = c.iterator();
        while (it.hasNext()) {
            Student s = it.next();
            System.out.println(s.getName()+"-"+s.getAge());
        }
    }
}
